package com.pan.cuiniubi.driver;

import com.pan.cuiniubi.create.dao.*;
import com.pan.cuiniubi.entity.MappingInfo;
import com.pan.cuiniubi.entity.Table;
import com.pan.cuiniubi.utils.WriterTool;

import java.util.List;

public class MappingDriver {
    public void outputMapping(Table table, CreateDaoMapping createDaoMapping){
        MappingInfo mappingInfo = createDaoMapping.getMappingInfo(table);
        String content = createDaoMapping.getMappingContent(mappingInfo);
        String myRootPath = System.getProperty("user.dir");
        String mappingPath = myRootPath+"\\output\\mapping\\"+mappingInfo.getClassName()+".xml";
        WriterTool.output(mappingPath,content);
    }


    public void outputSelectMapping(Table table){
        this.outputMapping(table,new CreateSelectDaoMapping());
    }
    public void outputSelectMapping(List<Table> tables){
        tables.stream().forEach(this::outputSelectMapping);
    }

    public void outputDeleteMapping(Table table){
        this.outputMapping(table,new CreateDeleteDaoMapping());
    }
    public void outputDeleteMapping(List<Table> tables){
        tables.stream().forEach(this::outputDeleteMapping);
    }

    public void outputUpdateMapping(Table table){
        this.outputMapping(table,new CreateUpdateDaoMapping());
    }
    public void outputUpdateMapping(List<Table> tables){
        tables.stream().forEach(this::outputUpdateMapping);
    }

    public void outputInsertMapping(Table table){
        this.outputMapping(table,new CreateInsertDaoMapping());
    }
    public void outputInsertMapping(List<Table> tables){
        tables.stream().forEach(this::outputInsertMapping);
    }
}
